<?php

class ContactusController extends Zend_Controller_Action {

    public function init() {
	/* Initialize action controller here */
    }

    public function indexAction() {
	global $config;
	$pubKey = $config->CAPTCHA_PUBLIC_KEY;
	$privKey = $config->CAPTCHA_PRIVATE_KEY;
	
	$recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey);
	$this->view->recaptcha = $recaptcha;

	$contactForm = new Form_ContactForm();
	$succesMeessage = "";
	$errorMessage = Array();
	if ($this->getRequest()->isPost()) {

	    if ($contactForm->isValid($_POST)) {

		try {
		    $result = $recaptcha->verify(
				    $_POST['recaptcha_challenge_field'],
				    $_POST['recaptcha_response_field']
		    );
		    if (!$result->isValid()) {
			$contactForm->addErrorMessage("Please Enter correct Captcha.");
			$errorMessage['0'] = $contactForm->getErrorMessages();
		    } else {

			$contactModel = new Model_Contact();
			// if the form is valid then create the new bug
			$result = $contactModel->createInquiry(
					$contactForm->getValue('name'),
					$contactForm->getValue('email'),
					$contactForm->getValue('subject'),
					$contactForm->getValue('message')
			);

			$body = "";
			$body .= "Name : " . $contactForm->getValue('name') . "<br/>";
			$body .= "Email : " . $contactForm->getValue('email') . "\r<br/>";
			$body .= "Subject : " . $contactForm->getValue('subject') . "\r<br/>";
			$body .= "Message : " . $contactForm->getValue('message') . "\r<br/>";

			$mail = new Zend_Mail();
			$mail->setBodyText($body);
			$mail->setBodyHtml($body, "iso-8859-1");
			$mail->setFrom('info@citrusbug.com', 'Info Citrus Bug');
			$mail->addTo('ketan.jems@gmail.com', 'Ketan Patel');
			$mail->addTo('vyasishanatc194@gmail.com', 'Vyas Ishan');
			$mail->addTo('info@citrusbug.com', 'Info Citrus Bug');
			$mailSubject = "Contact form Inquiry to Citrus Bug by [". $contactForm->getValue('name')."]";
			$mail->setReplyTo('info@citrusbug.com', 'Citrus Bug');
			$mail->addHeader('MIME-Version', '1.0');
			$mail->addHeader('Content-Transfer-Encoding', '8bit');
			$mail->addHeader('X-Mailer:', 'PHP/'.phpversion());
			$mail->setSubject($mailSubject);
			$mail->send();
			
			if ($result > 1) {
				$contactForm->reset();
				$succesMeessage = "Thanks for contacting us! Will be in touch soon.";
			}
		    }
		} catch (Exception $e) {
		    $contactForm->addErrorMessage("Please Enter Captcha.");
		    $errorMessage['0'] = $contactForm->getErrorMessages();
		}
	    } else {
		$errorMessage = $contactForm->getMessages();
	    }
	}

	$this->view->form = $contactForm;
	$this->view->errorMessage = $errorMessage;
	$this->view->succesMeessage = $succesMeessage;
	
	$this->view->showMetaDescription = TRUE;
	$this->view->showMetaKeyword = TRUE;
	$this->view->headTitle('Citrusbug Contact Us - Stay in Touch with Us');
	$this->view->META_DESCRIPTION = "Here you can drop as a line using contact form below to get our services for web application, web development, mobile application development, web design and many more...";
	$this->view->META_KEYWORDS = "web development, web design, mobile application development, seo, graphic design, offshore software development, PHP , linux programming, application development, usa, uk, canada, germany ,netherland , denmark";

	
	
    }

}

?>